package com.gregbugaj.tabwidget;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class TabWidgedLauncher extends Activity {
	protected static final String TAG = TabWidgedLauncher.class.getSimpleName();
	private Activity context;

	/* Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		context = this;
/*
 
		TabHost tabHost=new TabHost(
			new TabViewConfig()
			.context(context)
			.headerResourceId(R.drawable.tab_background_55)
			.orientation(TabHost.Orientation.BOTTOM)
		);
		
		TabHostProvider tabProvider=new CustomTabHostProvider(context);

		Tab t1=new Tab(context, "HOME");
		t1.setIcon(R.drawable.home);
		t1.setIntent(new Intent(context, TabWidgedLauncher.class));
		

		Tab t2=new Tab(context, "EDIT");
		t2.setIcon(R.drawable.edit_item);
		t2.setIntent(new Intent(context, One.class));

		Tab t3=new Tab(context, "HELP");
		t3.setIcon(R.drawable.help);
		t3.setIntent(new Intent(context, Two.class));
		
		tabHost.addTab(t1);
		tabHost.addTab(t2);
		tabHost.addTab(t3);

		tabHost.setCurrentView(R.layout.main);

 */
		TabHostProvider tabProvider=new CustomTabHostProvider(this);
		TabHost tabHost=tabProvider.getTabHost("main");
		Tab home=tabHost.getTab("HOME");
		home.setSelected(true);
		setContentView(tabHost.render());

		//setContentView(R.layout.table);
		//setContentView(buildTableViewFromXML());
		//setContentView(buildTableViewFromSourceCorrected());
	}

	private View buildTableViewFromSourceCorrected() {
		FrameLayout.LayoutParams pTable = new FrameLayout.LayoutParams(
			TableRow.LayoutParams.FILL_PARENT,
			TableRow.LayoutParams.FILL_PARENT);

		TableLayout table = new TableLayout(this);
		table.setBackgroundColor(Color.RED);
		table.setLayoutParams(pTable);

		TableRow rowTop = new TableRow(this);

		TableLayout.LayoutParams pRowTop = new TableLayout.LayoutParams(
			TableLayout.LayoutParams.FILL_PARENT,
			TableLayout.LayoutParams.WRAP_CONTENT);
		pRowTop.weight = 1;

		rowTop.setBackgroundColor(Color.BLUE);

		TextView txt = new TextView(this);
		txt.setText("Top Content");

		rowTop.addView(txt, new TableRow.LayoutParams(
			TableRow.LayoutParams.FILL_PARENT,
			TableRow.LayoutParams.WRAP_CONTENT));

		TableRow rowBottom = new TableRow(this);
		rowBottom.setBackgroundColor(Color.GREEN);

		TextView txtBottom = new TextView(this);
		txtBottom.setText("Bottom Content");

		TableLayout.LayoutParams pRowBottom = new TableLayout.LayoutParams(
			TableLayout.LayoutParams.WRAP_CONTENT,
			TableLayout.LayoutParams.WRAP_CONTENT);

		rowBottom.addView(txtBottom, new TableRow.LayoutParams(
			TableRow.LayoutParams.FILL_PARENT,
			TableRow.LayoutParams.WRAP_CONTENT));

		table.addView(rowTop, pRowTop);
		table.addView(rowBottom, pRowBottom);

		return table;
	}


	private View buildTableViewFromSource(){		
		TableRow.LayoutParams pTable=new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT);

		TableLayout table = new TableLayout(context);
		table.setBackgroundColor(Color.RED);
		table.setLayoutParams(pTable);


		TableRow rowTop = new TableRow(context);

		TableRow.LayoutParams pRowTop=new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT);
		pRowTop.height=TableRow.LayoutParams.FILL_PARENT;
		pRowTop.width=TableRow.LayoutParams.FILL_PARENT;
		pRowTop.weight=1;

		rowTop.setBackgroundColor(Color.BLUE);

		TextView txt=new TextView(context);
		txt.setText("Top Content");

		rowTop.addView(txt, pRowTop);

		TableRow rowBottom=new TableRow(context);
		rowBottom.setBackgroundColor(Color.GREEN);

		TextView txtBottom=new TextView(context);
		txtBottom.setText("Bottom Content");

		TableRow.LayoutParams pRowBottom=new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
		pRowBottom.height=TableRow.LayoutParams.WRAP_CONTENT;
		pRowBottom.width=TableRow.LayoutParams.FILL_PARENT;
		pRowBottom.weight=0;

		rowBottom.addView(txtBottom);

		table.addView(rowTop, pRowTop);
		table.addView(rowBottom, pRowBottom);

		return table;
	}
	/*
	private View buildTableViewFromXML(){
		LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		LinearLayout layout=(LinearLayout) inflater.inflate(R.layout.table, null);
		TableLayout table=(TableLayout) layout.findViewById(R.id.tableBottomLayout);
		layout.removeView(table);

		TableRow rowContent=(TableRow)table.findViewById(R.id.rowTop);

		TextView txt=new TextView(context);
		txt.setText("Top Content");
		rowContent.addView(txt);

		TableRow rowTabs=(TableRow)table.findViewById(R.id.rowBottom);


		TextView txtBottom=new TextView(context);
		txtBottom.setText("Bottom Content");
		rowTabs.addView(txtBottom);

		return table;
	}
	 */
}
